<?php


namespace App\Http\Controllers;

use App\Http\Resources\DeptCollection;
use App\Http\Services\DeptService;
use App\Http\Traits\ApiReturn;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class DeptController extends BaseController
{
    use ApiReturn;
    protected $service;
    public function __construct(Request $request,DeptService $deptService)
    {
        $this->service = $deptService;
        $this->request = $request;
        parent::__construct($request);
    }

    public function all()
    {
        $result = $this->service->all();
        return  $result;
    }
    public function tree()
    {
        $result = $this->service->tree();
        return  $this->succ($result);
    }

    public function options()
    {
        $result = $this->service->optionTree();
        return  $this->succ($result);
    }

    public function index()
    {
        $result = $this->service->list($this->request->all());
        return  new DeptCollection($result);
    }

    public function store(){
        $result = $this->service->store($this->request->all());
        return $this->succ($result);
    }

    public function update($id){
        $result = $this->service->store($this->request->all(),$id);
        return $this->succ($result);
    }

    public function detail($id){
        $result = $this->service->show($id);
        return $this->succ($result);

    }

    public function destroy($id){
        $result = $this->service->destroy($id);
        return $this->succ($result);
    }



}
